package com.yongcheon.sms_manager.receiver.phone;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.yongcheon.sms_manager.R;
import com.yongcheon.sms_manager.vo.SpamNumVO;

/**
 * Created by yongcheon on 2014-12-26.
 */
public class PhoneHandler extends Handler {

    private Context context;
    private SpamNumVO spamNumVO;
    private static RelativeLayout layout;
    private static Toast t;

    public PhoneHandler(Context context, SpamNumVO spamNumVO){
        this.context = context;
        this.spamNumVO = spamNumVO;

        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.receive_call, null);
        TextView spamCategory = (TextView)layout.findViewById(R.id.spam_category);
        spamCategory.setText(context.getResources().getString(R.string.spam_type)+" : "+spamNumVO.getCategory_2());
        TextView spamdesc = (TextView)layout.findViewById(R.id.spam_desc);
        spamdesc.setText(context.getResources().getString(R.string.spam_desc)+" : "+spamNumVO.getSubject());

        t = Toast.makeText(context.getApplicationContext(), "", Toast.LENGTH_LONG);
        t.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        t.setView(layout);
    }

    @Override
    public void handleMessage(Message msg) {
        if(msg.what == 0) {
            t.show();
        }
    }
}
